import React, { Component } from "react"
import "./index.css"
import PropTypes from "prop-types"

export default class Header extends Component {
  static propTypes = {
    add: PropTypes.func.isRequired,
  }
  keyup = (event) => {
    const { keyCode, target } = event
    if (keyCode !== 13) return
    if (target.value.trim() === "") return
    this.props.add(target.value)
    target.value = ""
  }
  render() {
    return (
      <section>
        <label>备忘录</label>
        <input onKeyUp={this.keyup} type="text" id="title" name="title" />
      </section>
    )
  }
}
